<template>
  <div class="container">
    <el-dialog
      title="线上付款"
      :visible.sync="sendPayDialog.dialogVisible"
      width="500px"
      center
      :lock-scroll="true"
      @open="getData"
      @close="hideDialog"
    >
      <el-form
        ref="formData"
        :rules="rules"
        :model="formData"
        label-width="150px"
        label-position="left"
      >
        <el-form-item label="短信验证码：" prop="classifyName">
          <el-input
            style="width: 200px"
            v-model="formData.classifyName"
            placeholder="请输入短信验证码"
          />
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="confirm()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {
  sendPayCode,
  onlineConfirmStatement,
} from "@/api/settlement/settlementList";

import { smkonlineConfirmStatement } from "@/api/superSettlement/settlementList";
export default {
  props: {
    sendPayDialog: Object,
  },
  data() {
    return {
      formData: {
        classifyName: "",
      },
      rules: {
        classifyName: [
          { required: true, message: "请填写短信验证码", trigger: "blur" },
        ],
      },
    };
  },

  methods: {
    getData() {
      let data = {
        amount: this.sendPayDialog.dialogPrince,
      };
      sendPayCode(data).then((res) => {
        if (res.code == 0) {
          this.$message({
            type: "success",
            message: res.message || res.msg,
          });
        }
      });
    },
    hideDialog() {
      this.sendPayDialog.dialogVisible = false;
      this.formData = {
        classifyName: "",
      };
    },
    //提交
    confirm() {
      if (!this.formData.classifyName) {
        this.$message({
          message: "请填写验证码",
          type: "success",
        });
        return;
      }

      let data = {
        jsonstr: this.sendPayDialog.dialogJsonstr,
        code: this.formData.classifyName,
        amount: this.sendPayDialog.dialogPrince,
      };
      console.log(this.sendPayDialog.dialogType, 33333);
      if (this.sendPayDialog.dialogType == "send") {
        onlineConfirmStatement(data).then((res) => {
          if (res.code == 0) {
            this.$message({
              message: res.msg || res.message,
              type: "success",
            });
            this.hideDialog();
            this.$emit("upData");
          } else {
            this.$message({
              message: res.msg || res.message,
              type: "error",
            });
          }
        });
      } else {
        smkonlineConfirmStatement(data).then((res) => {
          if (res.code == 0) {
            this.$message({
              message: res.msg || res.message,
              type: "success",
            });
            this.hideDialog();
            this.$emit("upData");
          } else {
            this.$message({
              message: res.msg || res.message,
              type: "error",
            });
          }
        });
      }
    },
    //取消
    cancel() {
      this.hideDialog();
    },
  },
};
</script>